package com.pets.springboot_petshop.mapper;

import com.pets.springboot_petshop.entity.Admin;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
/**
 * @Author: wxk
 * @Email: 2089967794@qq.com
 * @Date: 2024/10/8 上午9:44 周二
 * @Description: 管理员
 */
@Mapper
@Repository
public interface AdminMapper {
    //根据id查询用户
    @Select("SELECT * FROM admin WHERE id = #{id};")
    Admin select(int id);
    //根据用户名查询用户
    @Select("SELECT * FROM admin WHERE username = #{username};")
    Admin findByAdminName(String username);
    //根据用户邮箱查询用户
    @Select("select * from admin where email = #{email};")
    Admin findByAdminemail(String email);
    //根据用户名模糊查询用户
    @Select("SELECT * FROM admin WHERE username LIKE CONCAT('%', #{username}, '%');")
    List<Admin> selectusername(String username);
    //根据用户邮箱模糊查询用户
    @Select("select * from admin where email LIKE CONCAT('%', #{email}, '%');")
    List<Admin> selectemail(String email);
    //添加
    @Insert("insert into admin(username,password,role,email,create_time,update_time)values(#{username},#{password},#{role},#{email},now(),now());")
    void addAdmin(String username, String password, String role,String email);
    //查询所有
    @Select("select * from admin;")
    List<Admin> findAll();
    //修改管理员密码
    @Update("UPDATE admin SET password=#{password},update_time=now() WHERE email = #{email} ;")
    int updateAdminpassword(Admin admin);
    //修改管理员数据
    @Update("UPDATE admin SET username=#{username},email=#{email},role=#{role},update_time=now() where id= #{id};")
    int updateAdminById(Admin admin);
    //删除
    @Delete("delete from admin where id=#{id};")
    int deleteAdminById(int id);

}
